package com.web.base.wechat.util;

import com.blue.jdbc.Page;
import com.web.base.wechat.message.WechatMenuRequest;
import com.web.base.wechat.message.WechatMenuResponse;
import com.web.base.wechat.model.WechatMenu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 微信菜单转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月27日
 */
public class WechatMenuConvertor
{
	private WechatMenuConvertor()
	{
	}
	
	public static WechatMenu toWechatMenu(WechatMenuRequest request)
	{
		if (request == null)
			return null;
		
		WechatMenu wechatMenu = new WechatMenu();
		wechatMenu.setId(request.getId());
		wechatMenu.setParentId(request.getParentId());
		wechatMenu.setWechatId(request.getWechatId());
		wechatMenu.setName(request.getName());
		wechatMenu.setKey(request.getKey());
		wechatMenu.setUrl(request.getUrl());
		wechatMenu.setDescp(request.getDescp());
		wechatMenu.setState(request.getState());
		wechatMenu.setType(request.getType());
		wechatMenu.setSort(request.getSort());
		return wechatMenu;
	}
	
	public static WechatMenuResponse toResponse(WechatMenu wechatMenu)
	{
		if (wechatMenu == null)
			return null;
		
		WechatMenuResponse response = new WechatMenuResponse();
		response.setId(wechatMenu.getId());
		response.setParentId(wechatMenu.getParentId());
		response.setWechatId(wechatMenu.getWechatId());
		response.setName(wechatMenu.getName());
		response.setKey(wechatMenu.getKey());
		response.setUrl(wechatMenu.getUrl());
		response.setDescp(wechatMenu.getDescp());
		response.setState(wechatMenu.getState());
		response.setType(wechatMenu.getType());
		response.setSort(wechatMenu.getSort());

		response.setParentName(wechatMenu.getParentName());
		response.setWechatName(wechatMenu.getWechatName());
		return response;
	}
	
	public static List<WechatMenuResponse> toResponse(List<WechatMenu> list)
	{
		List<WechatMenuResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (WechatMenu wechatMenu : list)
		{
			responseList.add(toResponse(wechatMenu));
		}
		return responseList;
	}
	
	public static Map<String, List<WechatMenuResponse>> toResponse(Map<String, List<WechatMenu>> map)
	{
		Map<String, List<WechatMenuResponse>> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<String, List<WechatMenu>> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<WechatMenuResponse> toResponse(Page<WechatMenu> page)
	{
		if (page == null)
			return null;
		
		Page<WechatMenuResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
